package com.teach.food.service.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.teach.dto.CommentsSearch;
import com.teach.entity.Comments;
import com.teach.exception.CodeException;
import com.teach.mapper.CommentsMapper;
import com.teach.food.service.CommentsService;
@Service("food")
public class CommentsServiceImpl implements CommentsService{
	@Autowired
	private CommentsMapper mapper;

	@Override
	public List<Comments> commentsAllList(CommentsSearch commentsSearch) throws CodeException {
		return mapper.selectAll(commentsSearch);
	}

	@Override
	public List<Comments> list(int startIndex, int len) {
		PageInfo<Comments> pageInfo = PageHelper.offsetPage(startIndex, len).setCount(false).doSelectPageInfo(()->mapper.select(null));
		return pageInfo.getList();
	}

	@Override
	public PageInfo<Comments> page(int current, int rowMax) {
		return PageHelper.startPage(current, rowMax).doSelectPageInfo(()->mapper.select(null));
	}

	@Override
	public PageInfo<Comments> pageSearch(CommentsSearch search) {
		return PageHelper.startPage(search.getCurrent(), search.getRowMax()).doSelectPageInfo(()->mapper.selectAll(search));
	}
	
}
